
layui.use(['element','form','upload','layedit'], function () {
     var element = layui.element,
     					form = layui.form,
     					upload = layui.upload,
     					layedit = layui.layedit;

    $.ajax({
        url: "jobConfig/get",
        type: 'get',
        dataType: "json",
        success: function (data) {
            if(data.rel){
                setInputValues(data.result);

                if(data.result.delFlg==0){
                    $("input[name='delFlg'][value='0']").attr('checked',true);
                    form.render();
                }else{
                    $("input[name='delFlg'][value='1']").attr('checked',true);
                    form.render();
                }
            }else{
                layerTips.msg(data.msg);
            }
        }
    });

     form.on('submit(save)', function(data){
        submitForm(data);
       return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
     });
});

function submitForm(data){
  $.ajax({
     url: 'jobConfig/update',
     type: 'put',
      data: data.field,
      dataType: "json",
     success: function (data) {
         var layerTips = parent.layer === undefined ? layui.layer : parent.layer;
         if(data.rel){
            layerTips.msg('处理成功');
         }else{
           layerTips.msg(data.msg);
         }
     }
   });
}

function setLabelValues(data) {
    for (var p in data) {
        $("#" + p + "").html(data[p]);
    }
}

function setInputValues(data) {
    for (var p in data) {
        $("#" + p + "").val(data[p]);
    }
}



